package com.hs.system.api.entity;

import java.time.LocalDateTime;
import javax.validation.constraints.*;

import com.baomidou.mybatisplus.annotation.*;
import com.hs.common.core.annotation.Excel;
import com.hs.common.core.annotation.Excel.Type;
import com.hs.common.core.annotation.Excel.ColumnType;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import static com.hs.common.core.constant.UserConstants.*;

import com.hs.common.core.xss.Xss;

/**
 * 用户对象 system
 */
@Data
public class User {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 用户邮箱
     */
    @Excel(name = "用户邮箱")
    private String email;

    /**
     * 密码
     */
    private String password;

    /**
     * 用户账号
     */
    @Excel(name = "用户昵称")
    private String nickname;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 帐号状态（1正常 0停用,2删除）
     */
    @Excel(name = "帐号状态", readConverterExp = "1=正常,0=停用,2=删除")
    @TableLogic(value = "1",delval = "2")
    private String status;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP", type = Type.EXPORT)
    private String loginIp;

    /**
     * 最后登录时间
     */
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
    private LocalDateTime loginDate;


    public User() {

    }

    public User(long id) {
        this.id = id;
    }

    @Email(message = "邮箱格式不正确")
    @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH, message = EMAIL_NOTE)
    public String getEmail() {
        return email;
    }

    @NotBlank(message = "用户密码不能为空")
    @Size(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH, message = PASSWORD_NOTE)
    public String getPassword() {
        return password;
    }

    @Xss(message = "昵称不能包含脚本字符")
//    @NotBlank(message = "昵称不能为空")
    @Size(min = 0, max = 30, message = "昵称不能超过30个字符")
    public String getNickname() {return nickname;}

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("userId", getId())
                .append("email", getEmail())
                .append("password", getPassword())
                .append("nickname", getNickname())
                .append("avatar", getAvatar())
                .append("status", getStatus())
                .append("loginIp", getLoginIp())
                .append("loginDate", getLoginDate())
                .toString();
    }
}
